package com.bootlever.framework.core.configuration;

import com.bootlever.framework.core.properties.BasicProperties;
import com.bootlever.framework.core.template.MailTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.mail.internet.AddressException;

@Configuration
public class MailTemplateConfiguration {

    private static final Logger logger = LoggerFactory.getLogger(MailTemplateConfiguration.class);

    @Autowired
    private BasicProperties basicProperties;

    @Bean
    public MailTemplate mailTemplate() throws AddressException {
        MailTemplate mailTemplate = new MailTemplate();
        boolean isMailEnabled = mailTemplate.init(basicProperties);
        if (isMailEnabled == false) {
            return null;
        }
        logger.info("初始化MailTemplate完成");
        return mailTemplate;
    }
}
